package com.qk.management.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qk.common.PageResult;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.mapper.ActivityMapper;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 *
 * @author sch
 * @version 1.0
 * @since 2025-10-09-14:49
 */
@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;


    @Override
    public PageResult<Activity> listActivity(ActivityDTO activityDTO) {
        PageHelper.startPage(activityDTO.getPage(), activityDTO.getPageSize());
        List<Activity> activities = activityMapper.selectByCondition(activityDTO);
        PageInfo<Activity> pageInfo = new PageInfo<>(activities);
        return new PageResult<>(pageInfo.getTotal(), pageInfo.getList());

    }

    @Override
    public void deleteActivity(Integer id) {
        activityMapper.deleteById(id);
    }

    @Override
    public void addActivity(Activity activity) {
        activity.setCreateTime(LocalDateTime.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.insert(activity);
    }

    @Override
    public Activity getActivityById(Integer id) {
        return activityMapper.selectById(id);
    }

    @Override
    public void updateActivity(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.update(activity);
    }

    @Override
    public List<Activity> listActivitiesByType(Integer type) {
        return activityMapper.listActivitiesByType(type);
    }
}
